package com.moive.news.tqnewsapplication.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.moive.news.tqnewsapplication.R;
import com.moive.news.tqnewsapplication.entity.DyReleaseEntity;

import java.util.List;

/**
 * Created by Administrator on 2017/12/14.
 */

public class FenLeiAdapter extends RecyclerView.Adapter<FenLeiAdapter.FenleiHelder> {
    private List<String> list;
    private Context context;
    private OnItemClickListener onItemClickListener;

    public FenLeiAdapter(List<String> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public FenleiHelder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_fenlei, null, false);
        FenleiHelder v = new FenleiHelder(view);
        v.setIsRecyclable(true);
        return v;
    }

    @Override
    public void onBindViewHolder(FenleiHelder holder, int position) {
        holder.fenlei_text.setText(list.get(position).toString());
        if (position == 0) {
            holder.fenlei_img.setBackgroundResource(R.drawable.type_top);
        } else if (position == 1) {
            holder.fenlei_img.setBackgroundResource(R.drawable.type_tuijian);
        } else if (position == 2) {
            holder.fenlei_img.setBackgroundResource(R.drawable.type_yule);
        } else if (position == 3) {
            holder.fenlei_img.setBackgroundResource(R.drawable.type_nvyou);
        } else if (position == 4) {
            holder.fenlei_img.setBackgroundResource(R.drawable.type_caijin);
        } else if (position == 5) {
            holder.fenlei_img.setBackgroundResource(R.drawable.type_food);
        }
        if (onItemClickListener != null) {
            holder.fenlei_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onItemClickListener.onItemClick(v, holder.getPosition());
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class FenleiHelder extends RecyclerView.ViewHolder {
        ImageView fenlei_img;
        TextView fenlei_text;

        public FenleiHelder(View itemView) {
            super(itemView);
            fenlei_img = itemView.findViewById(R.id.fenlei_img);
            fenlei_text = itemView.findViewById(R.id.fenlei_text);
        }


    }

    public interface OnItemClickListener {
        void onItemClick(View view, int id);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }
}
